# -*- encoding=utf8 -*-
        
__author__ = "Bryan.Chen"
__desc__=""
        
from airtest.core.api import *
        
auto_setup(__file__)
        
from poco.drivers.std import StdPoco
poco = StdPoco()
        
using("../FlowTest.air")
import FlowTest
        
class Task_FinishTask(FlowTest.BaseTestCase):
    def __init__(self):
        print("%s __init__" % (__file__))
        
    def runTest(self, args):
        print("%s runTest" % (__file__))
        btnMoreMission = poco("more_mission")
        if btnMoreMission.exists():
            self.clickButton(btnMoreMission)

        try:
            poco("MissionCenterLayer").wait_for_appearance()
        except:
            assert_equal(False, True, "任务中心正常弹出")
            return False

        missionCenterLayer = poco("MissionCenterLayer")

        # 做一个任务
        taskList = missionCenterLayer.offspring("task_list")
        taskItems = taskList.offspring("template")
        for i in range(0, len(taskItems)):
            txtName = taskItems[i].child("name").get_text()
            if txtName == "每日分享":
                btnToDo = taskItems[i].offspring("todo_btn")
                self.clickButton(btnToDo)

                sleep(2.0)
                
                assert_exists(Template(r"tpl1534746358891.png", record_pos=(-0.277, -0.614), resolution=(1080, 1920)), "请填写测试点")

                touch(Template(r"tpl1534746358891.png", record_pos=(-0.277, -0.614), resolution=(1080, 1920)))
                
                text("自动化测试-完成每日分享任务")

                assert_exists(Template(r"tpl1534746278650.png", record_pos=(0.419, -0.751), resolution=(1080, 1920)), "弹出分享界面")

                touch(Template(r"tpl1534746278650.png", record_pos=(0.419, -0.751), resolution=(1080, 1920)))
            
                break

        snapshot()

        titleBar = missionCenterLayer.offspring("titile_bar")
        btnClose = titleBar.offspring("back")
        if btnClose.exists():
            self.clickButton(btnClose)

        return True
        
_instance = Task_FinishTask()
runTest = _instance.runTest


